package com.itrip.itripauth.util;

import com.itrip.common.vo.UserVo;
import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @program: itrip-parent
 * @description: 验证token
 * @author: joker
 * @create: 2020-03-12 16:56
 **/
@Component
public class TokenUtil {

    @Resource
    private RedisUtil redisUtil;
    public UserVo verifyToken(String token){
        UserVo userVo=null;
        try {
            //验证token是否过期
            System.out.println("token:"+token);
            //验证token
            Claims claims = JwtUtil.checkToken(token);
            System.out.println(claims);
            claims.remove(claims.getSubject());
            userVo=(UserVo) redisUtil.get(token);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            return userVo;
        }
    }
}
